#ifndef PERMUTATIONS_H 
#define PERMUTATIONS_H

#include <vector>
#include "Permutation.h"
#include "XmlDefinitions.h"
#include "Chain.h"
#include <string>
#include "./Markup/Markup.h"

using std::string;

class Permutations
{
public:
	Permutations(unsigned long *originalPermutation,int wordLen, int groupSize, int maxIntersectionForSave, int minChainLengthForSave, int maxChains);
	~Permutations(void);
	int GetGroupSize() const; 
	int GetMaxIntersection() const { return m_MaxIntersectionForSave; };
	int GetMaxChains() const { return m_MaxChains; };
	int GetMinChainLength() const { return m_MinChainLengthForSave; };
	void InsertPerm(const Permutation &perm);
	Permutation *GetOriginalPermutation();
	vector<Permutation> GetPermutations() {return m_Permutations;};
	void Fill();
	void CreateAllChains();
	void SaveToFile(string filename);
	void SaveGroups(string filename);
	static Permutations *CreatePermutationsObject(CMarkup &xmlFile);
	void Run(string outputFileName);

private:
	int m_WordLen; // How long is each binary word - column count
	int m_OriginalGroupSize; // How many words are in original group
	int m_MaxIntersectionForSave; // The largest intersection with the original group we allow 
	int m_MinChainLengthForSave; // The minimal chain length for a chain to be saved
	int m_MaxChains; // The maximal number of chains to save
	vector<Permutation> m_Permutations;
	vector<Chain> m_Chains;
	CMarkup m_Xml; // For saving 
	
	int CreateChains(Permutation *perm, Chain chain, int chainCount);
	void AddPermutationToList(Permutation *perm, int intersectionWithOriginal);
};

#endif
